$.ajax({
    type:'get',
    url:'/mywork.json/',
    dataType:'json',
    success:function(data){
        $('#username').text(data.username);
        $('#profile').prop('src', data.profile);
        for (const i of data.recommand) {
            let field = ''; for (const j of i.field) field += '<br>' + j;
            $('#hint').after(`
            <div class="card mb-3">
                <div class="card-body">
                    <h5 class="card-title">${i.name}</h5>
                    <h6 class="card-subtitle text-muted">Last update: ${i.time}</h6>
                </div>
                <ul class="list-group list-group-flush">
                    <li class="list-group-item"><strong>Description: </strong><p>${i.description}</p></li>
                    <li class="list-group-item"><strong>Content: </strong>${i.content}</li>
                    <li class="list-group-item"><strong>Contribute: </strong>${i.num} contributes</li>
                    <li class="list-group-item"><strong>Field: </strong>${field}</li>
                </ul>
                <div class="p-3" id="${i.id}">
                    <a href="/detail.htm?id=${i.id}" class="btn btn-primary">Detail</a>
                    <button type="button" class="btn btn-danger remove">Remove</button>
                </div>
            </div>`);
            $('#' + i.id).find('.remove').click(function () {
                $.ajax({
                    type: 'post',
                    url: '/remove/',
                    data: i.name,
                    dataType: 'text',
                    success: function(data) {
                        if (data == 'success') location.reload(); else alert(data);
                    },
                    error: function (http, e) {
                        alert(http.status + e);
                    }
                });
            });
        }
    }
});
$('#logout').click(function () {
    let t = new Date();
    t.setTime(t.getTime() - 1);
    document.cookie = 'username=-1;expires=' + t.toUTCString();
    document.cookie = 'password=-1;expires=' + t.toUTCString();
});
